package com.copyctrl.campus.portal.controller;

import cn.hutool.json.JSONUtil;
import com.copyctrl.campus.common.model.ApiResponse;
import com.copyctrl.campus.portal.service.GetService;
import com.copyctrl.model.CampGet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author:JH
 * @version:1.0
 */
@RestController
@RequestMapping("/get")
public class ThingsGetController {
    @Autowired
    GetService service;

    @PostMapping("/{get}")
    public ApiResponse add(@PathVariable String get){
        CampGet campGet = JSONUtil.toBean(get, CampGet.class);
        int add = service.add(campGet);
        return add==1?ApiResponse.ofSuccess("ok"):ApiResponse.ofFailure("失败");
    }

    @GetMapping("/{id}")
    public ApiResponse getById(@PathVariable Integer id){
        return ApiResponse.ofSuccess(service.findByGid(id));
    }
}
